Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald-tests\distribution-tests.cpp
Line
Count
Source
1
//  Copyright 2021 Herald Project Contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#include <iostream>
6
#include <fstream>
7
#include <string>
8
9
#include "catch.hpp"
10
11
#include "herald/herald.h"
12
13
1
TEST_CASE("distribution-empty", "[distribution][datatype][empty]") {
14
1
  SECTION("distribution-empty") {
15
1
    herald::datatype::Distribution d;
16
1
17
1
    REQUIRE(0 == d.count());
18
1
    REQUIRE(0.0 == d.mean());
19
1
    REQUIRE(0.0 == d.variance());
20
1
    REQUIRE(0.0 == d.standardDeviation());
21
1
    REQUIRE(0.0 != d.min());
22
1
    REQUIRE(0.0 != d.max());
23
1
  }
24
1
}
25
26
1
TEST_CASE("distribution-single", "[distribution][datatype][single]") {
27
1
  SECTION("distribution-single") {
28
1
    herald::datatype::Distribution d;
29
1
30
1
    d.add(5);
31
1
32
1
    REQUIRE(1 == d.count());
33
1
    REQUIRE(5.0 == d.mean());
34
1
    REQUIRE(0.0 == d.variance());
35
1
    REQUIRE(0.0 == d.standardDeviation());
36
1
    REQUIRE(5.0 == d.min());
37
1
    REQUIRE(5.0 == d.max());
38
1
  }
39
1
}
40
41
1
TEST_CASE("distribution-sevens", "[distribution][datatype][sevens]") {
42
1
  SECTION("distribution-sevens") {
43
1
    herald::datatype::Distribution d(7,9);
44
1
45
1
    REQUIRE(9 == d.count());
46
1
    REQUIRE(7.0 == d.mean());
47
1
    REQUIRE(0.0 == d.variance());
48
1
    REQUIRE(0.0 == d.standardDeviation());
49
1
    REQUIRE(7.0 == d.min());
50
1
    REQUIRE(7.0 == d.max());
51
1
  }
52
1
}
53
54
1
TEST_CASE("distribution-geometric", "[distribution][datatype][geometric]") {
55
1
  SECTION("distribution-geometric") {
56
1
    herald::datatype::Distribution d;
57
1
58
1
    d.add(1);
59
1
    d.add(2);
60
1
    d.add(4);
61
1
    d.add(8);
62
1
    d.add(16);
63
1
64
1
    REQUIRE(5 == d.count());
65
1
    REQUIRE(6.2 == d.mean());
66
1
    REQUIRE(37.2 == d.variance());
67
1
    REQUIRE(6.099 < d.standardDeviation());
68
1
    REQUIRE(6.1 > d.standardDeviation());
69
1
    REQUIRE(1.0 == d.min());
70
1
    REQUIRE(16.0 == d.max());
71
1
  }
72
1
}
73
74
1
TEST_CASE("distribution-add", "[distribution][datatype][add]") {
75
1
  SECTION("distribution-add") {
76
1
    herald::datatype::Distribution d1;
77
1
    herald::datatype::Distribution d2;
78
1
79
1
    d1.add(1);
80
1
    d1.add(2);
81
1
    d1.add(4);
82
1
    d2.add(8);
83
1
    d2.add(16);
84
1
85
1
    d1.add(d2);
86
1
87
1
    REQUIRE(5 == d1.count());
88
1
    REQUIRE(6.2 == d1.mean());
89
1
    // Note - variance varies slightly because we're making up the difference in the add function
90
1
    INFO("variance is " << d1.variance());
91
1
    REQUIRE(37.199 < d1.variance());
92
1
    REQUIRE(37.201 > d1.variance());
93
1
    REQUIRE(6.099 < d1.standardDeviation());
94
1
    REQUIRE(6.1 > d1.standardDeviation());
95
1
    REQUIRE(1.0 == d1.min());
96
1
    REQUIRE(16.0 == d1.max());
97
1
98
1
    std::string about = d1;
99
1
    INFO(about);
100
1
    REQUIRE("" != about);
101
1
  }
102
1
}
103
104
1
TEST_CASE("distribution-reset", "[distribution][datatype][reset]") {
105
1
  SECTION("distribution-reset") {
106
1
    herald::datatype::Distribution d;
107
1
108
1
    d.add(5);
109
1
110
1
    d.reset();
111
1
112
1
    REQUIRE(0 == d.count());
113
1
    REQUIRE(0.0 == d.mean());
114
1
    REQUIRE(0.0 == d.variance());
115
1
    REQUIRE(0.0 == d.standardDeviation());
116
1
    REQUIRE(0.0 != d.min());
117
1
    REQUIRE(0.0 != d.max());
118
1
  }
119
1
}